package org.springblade.pm.wrappper;

import org.springblade.common.constant.CommonConstant;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.pm.entity.File;
import org.springblade.pm.vo.FileVo;

import java.util.ArrayList;
import java.util.List;


public class FileWrapper extends BaseEntityWrapper<File,FileVo> {

	public static FileWrapper build() {
		return new FileWrapper();
	}
	@Override
	public FileVo entityVO(File file) {
		FileVo fileVo = BeanUtil.copy(file, FileVo.class);
		String path = file.getPath();
		fileVo.setUrl("/api/" + CommonConstant.APPLICATION_OA_NAME + "/image/" + path.substring(path.lastIndexOf("/", path.lastIndexOf("/") - 1) + 1));
		return fileVo;
	}

	/**
	 * 任务书列表数据包装
	 *
	 * @param list
	 * @return
	 */
	public List<FileVo> entityVOList(List<File> list) {
		List<FileVo> fileVoList = new ArrayList<>();
		for (File file : list) {
			fileVoList.add(entityVO(file));
		}
		return fileVoList;
	}
}
